package com.uflower.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import com.uflower.order.entity.OrderEntity;
import com.uflower.order.entity.OrderItemEntity;
import com.uflower.order.interceptor.LoginUserInterceptor;
import com.uflower.order.service.OrderItemService;
import com.uflower.order.service.OrderService;
import com.uflower.order.vo.OrderVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Controller
public class PageController {

    @RequestMapping("/confirm")
    public String confirm(){
        return  "confirm";
    }
    @RequestMapping("/confirm1")
    public String confirm1(){
        return  "confirm1";
    }
    @RequestMapping("/waitForPay")
    public String waitForPay(){
        return "waitForPay";
    }
    @RequestMapping("/pay")
    public String pay(){
        return "pay";
    }
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderItemService orderItemService;
    @ApiOperation("跳转到订单中心")
    @GetMapping("/myorders")
    public String myOrdersPage(Model model){
        List<OrderEntity> orderEntities = new ArrayList<>();
        List<OrderEntity> orders = orderService.getOrdersById(LoginUserInterceptor.loginUser.get().getId());
        for (OrderEntity orderEntity: orders){
            OrderItemEntity orderItem = orderItemService.getByOrderSn(orderEntity.getOrderSn());
            orderEntity.setOrderItemEntity(orderItem);
            orderEntities.add(orderEntity);
        }
        System.out.println("*********************"+orderEntities+"***************");
        model.addAttribute("orders",orderEntities);
        return "myorders";
    }
}
